// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import Myaxios from '@/assets/js/axios.js'
import '../node_modules/element-ui/lib/theme-chalk/index.css'
import	'@/assets/css/reset.css'
//视频
import VideoPlayer from 'vue-video-player'
//iconfont
import './assets/iconfont/iconfont.css'
//import 'video.js/dist/video-js.css'
//富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.use(VideoPlayer)
Vue.use(ElementUI)
Vue.use(Myaxios)
//富文本编辑器
Vue.use(VueQuillEditor, /* { default global options } */)
Vue.config.productionTip = false
//echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts


//Vue.prototype.baseURL = process.env.API_ROOT;
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

//路由导航
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
    if(sessionStorage.getItem('token')){ //判断本地是否存在token
      next();
    }else {
      if(to.path === '/login'){
        next();
      }else {
        next({
          path:'/login'
        })
      }
    }
  }else {
    next();
  }
  /*如果本地 存在 token 则 不允许直接跳转到 登录页面*/
  if(to.fullPath == "/login"){
    if(sessionStorage.getItem('token')){
      next({
        path:from.fullPath
      });
    }else {
      next();
    }
  }
});
